/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VerEditarCarreta.java
 *
 * Created on 29-mar-2012, 1:28:17
 */
package Ventas;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author macbookpro
 */
public class VerEditarCarreta extends javax.swing.JFrame {
public ArrayList<DatosCarreta> Carretillaedicion;
public ArrayList<DatosCarreta> Carretilladefecto;
/** Creates new form VerEditarCarreta */
    public VerEditarCarreta() {
        Carretillaedicion=new ArrayList<DatosCarreta>();//carretilla que se va a editar y esas cosas
        Carretillaedicion=(ArrayList<DatosCarreta>)Carretilla.CarretillaActual.clone();
        Carretilladefecto= new ArrayList<DatosCarreta>();//carretilla por si se quiere vovler a la que se tenia originalmente
        Carretilladefecto=(ArrayList<DatosCarreta>)Carretilla.CarretillaActual.clone();
        initComponents();
    this.llenacarreta();
    
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}

            },
            new String [] {
                "Codigo", "Nombre", "Tipo", "Marca", "Precio Venta", "Existencia", "Descripcion"
            }
        )

    );
    jTable1.setName("jTable1"); // NOI18N
    jScrollPane1.setViewportView(jTable1);

    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(tiendaingsoftii.TiendaINGSOFTIIApp.class).getContext().getResourceMap(VerEditarCarreta.class);
    jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
    jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
    jLabel1.setName("jLabel1"); // NOI18N

    jButton1.setFont(resourceMap.getFont("jButton1.font")); // NOI18N
    jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
    jButton1.setName("jButton1"); // NOI18N
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jButton2.setFont(resourceMap.getFont("jButton2.font")); // NOI18N
    jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
    jButton2.setName("jButton2"); // NOI18N
    jButton2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton2ActionPerformed(evt);
        }
    });

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(layout.createSequentialGroup()
            .addContainerGap()
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .add(jLabel1)
                    .add(256, 256, 256))
                .add(layout.createSequentialGroup()
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 726, Short.MAX_VALUE)
                    .add(30, 30, 30))
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 723, Short.MAX_VALUE)
                        .add(jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 723, Short.MAX_VALUE))
                    .add(33, 33, 33))))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(layout.createSequentialGroup()
            .addContainerGap()
            .add(jLabel1)
            .add(18, 18, 18)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 208, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .add(14, 14, 14)
            .add(jButton1)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
            .add(jButton2)
            .addContainerGap())
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

              if((jTable1.getSelectedRow() >= 0)){//si no se hace la busqueda
    if ((jTable1.getValueAt(jTable1.getSelectedRow(),1) !=null)){//a nivel de objetos se compara si es nula la casilla
        
 for(int i=0; i<Carretillaedicion.size();i++){
 if(jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString().compareTo(Carretillaedicion.get(i).getCodigo())==0) {
 Carretillaedicion.remove(i);  //si lo encuentra lo remueve
 Carretilla.CarretillaActual=(ArrayList<DatosCarreta>)Carretillaedicion.clone();//clono el array de objetos
 break;
 }
 
 }
        
    JOptionPane.showMessageDialog(null, "Producto Borrado Exitosamente");

}else{
    JOptionPane.showMessageDialog(null, "Casilla en Blanco, por favor seleccione un producto");
    
    }
        
        
        }else{
        
         JOptionPane.showMessageDialog(null, "Por Favor busque un producto y luego seleccionelo para agregarlo a Carretilla");
   
        } 
    this.llenacarreta();
        
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
Carretilla.CarretillaActual=(ArrayList<DatosCarreta>)Carretilladefecto.clone();
Carretillaedicion=(ArrayList<DatosCarreta>)Carretilladefecto.clone();
this.llenacarreta();        
        
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    
    public void llenacarreta(){
    
        
                    Vector tableData = new Vector();
                    Vector<String> tableHeaders = new Vector<String>();
                    
                    
                    
                    tableHeaders.add("Codigo");
                    tableHeaders.add("Nombre");
                    tableHeaders.add("Tipo");
                    tableHeaders.add("Marca");
                    tableHeaders.add("Precio Venta");
                    tableHeaders.add("Existencia");
                    tableHeaders.add("Descripcion");
                    
                    
                    Vector<Object> oneRow = null;
                    
                     
                             
    for(int i=0; i<Carretillaedicion.size();i++){
        
            oneRow = new Vector<Object>();
                        oneRow.add(Carretillaedicion.get(i).getCodigo());
                        oneRow.add(Carretillaedicion.get(i).getNombre());
                        oneRow.add(Carretillaedicion.get(i).getTipo());
                        oneRow.add(Carretillaedicion.get(i).getMarca());
                        oneRow.add(Carretillaedicion.get(i).getPrecioventa());
                        oneRow.add(Carretillaedicion.get(i).getExistencia());
                        oneRow.add(Carretillaedicion.get(i).getDescripcion());
                        
                        
                        tableData.add(oneRow);
                     
    
    }
                    
                    
                    jTable1.setModel(new MiModelo(tableData, tableHeaders));
               
        
   
    
    
    }
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new VerEditarCarreta().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    public static javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
